export function backTop() {
    var timer = setInterval(function(){
      let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
      let scrollMove = Math.floor(-scrollTop / 5); 
      document.documentElement.scrollTop = document.body.scrollTop = scrollTop + scrollMove;
      if(scrollTop === 0){
        clearInterval(timer);
      }
    },30);
}

// 倒计时
const timeFormat = (param) => {
  return param < 10 ? '0' + param : param;
}
export function countdown(endTime, ms) {
  let nowTime = new Date().getTime(), obj;
  // 获取时间差、天、时、分、秒
  if (endTime - nowTime > 0) {
    let time = (endTime - nowTime) / 1000; 
    let day = parseInt(time / (60 * 60 * 24)); 
    let hour = parseInt(time % (60 * 60 * 24) / 3600); 
    let min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
    let sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);   
      
    obj = {
      day: timeFormat(day),
      hour: timeFormat(hour),
      min: timeFormat(min),
      sec: timeFormat(sec),
      ms: timeFormat(ms)
    };
  } else {
    obj = {
      day: '00',
      hour: '00',
      min: '00',
      sec: '00',
      ms: '00',
      stop: true
    }
  }
  return obj;
}